<?xml version="1.0" encoding="UTF-8" ?>
<!-- Example:
<componentlist>
  <hddDrive>
    <hdd>
        <id>1</id>   
        <name>hdd_1</name>
        <price>1000</authorsurname>
        <manName>DELL</authorname>
        <count>23</price>
    </hdd>
    <hdd>
        <id>2</id>   
        <name>hdd_2</name>
        <price>3000</authorsurname>
        <manName>SAMSUNG</authorname>
        <count>10</price>
    </hdd>
  <hddDrive>
  
  <motherboards>
  .....
  <motherboards>
  
</componentlist>
-->


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html"/>

  <xsl:template match="componentlist">
    <head>
		<script language="JavaScript">
			<![CDATA[
				function getRadioButtonsValues(frm){
					var hdd_length = frm.hdd_radio.length;
					var motherboard_length = frm.motherboard_radio.length;
					var processor_length = frm.processor_radio.length;
					var ram_length = frm.ram_radio.length;
					var videocard_length = frm.videocard_radio.length;
					
					for (var i=0; i < hdd_length; i++){
						if (frm.hdd_radio[i].checked){
						var hdd_id = document.getElementById("componentlist_table").rows[i+1].cells[2].firstChild.value;	
						}
					}
					
					for (var i=0; i < motherboard_length; i++){
						if (frm.motherboard_radio[i].checked){
						var mb_id = document.getElementById("componentlist_table").rows[i+1].cells[2].firstChild.value;
						}
					}	
					
					for (var i=0; i < processor_length; i++){
						if (frm.processor_radio[i].checked){
							var proc_id = document.getElementById("componentlist_table").rows[i+1].cells[2].firstChild.value;
						}
					}
					for (var i=0; i < ram_length; i++){
						if (frm.ram_radio[i].checked){
							var ram_id = document.getElementById("componentlist_table").rows[i+1].cells[2].firstChild.value;
						}
					}
					for (var i=0; i < videocard_length; i++){
						if (frm.videocard_radio[i].checked){
							var vc_id = document.getElementById("componentlist_table").rows[i+1].cells[2].firstChild.value;
						}
					}
					//alert(hdd_id +"\n"+ mb_id +"\n"+ proc_id +"\n"+ ram_id +"\n"+ vc_id);
					var link = "shop?action=add&hdd_id=" + hdd_id + "&mb_id=" + mb_id + "&proc_id=" + proc_id + "&ram_id=" + ram_id + "&vc_id=" + vc_id;
                    
					document.componentlist_form.action=link;
					document.componentlist_form.method="POST";
					document.componentlist_form.submit(); 
                }
			]]>
		</script>
	</head>
    <form method="post" action="shop" name="componentlist_form">
    <table border = "0" cellspacing = "10" id = "componentlist_table" align = "center" bgcolor="CornflowerBlue">
        <tr bgcolor="silver"><td colspan = "2"><b>Hard Drives:  </b></td></tr>
            <xsl:for-each select="hardDrives/hdd">
              <tr>
                <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">radio</xsl:attribute>
                      <xsl:if test="position()=1">
                         <xsl:attribute name="checked">checked</xsl:attribute>
                      </xsl:if>
                      <xsl:attribute name="name">hdd_radio</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="name"/></xsl:attribute>              
                    <xsl:value-of select="name"/>
                    </xsl:element>
                </td>
                <td>    
                    <!-- Details Links -->
                    <xsl:element name="a">
                      <xsl:attribute name="href">
                          <xsl:text disable-output-escaping="yes"><![CDATA[shop?action=detail_hdd&id=]]></xsl:text><xsl:value-of select="id"/></xsl:attribute>
                      <xsl:text>Details</xsl:text>
                    </xsl:element>
                </td>
                <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">hidden</xsl:attribute>
                      <xsl:attribute name="name">hdd_id</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>              
                    </xsl:element>
                </td>    
              </tr>
            </xsl:for-each>
                
        
        <tr bgcolor="silver"><td colspan = "2"><b>Motherboards:  </b></td></tr>
            <xsl:for-each select="motherboards/motherboard">
               <tr>
                  <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">radio</xsl:attribute>
                      <xsl:if test="position()=1">
                         <xsl:attribute name="checked">checked</xsl:attribute>
                      </xsl:if>
                      <xsl:attribute name="name">motherboard_radio</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="name"/></xsl:attribute>              
                    <xsl:value-of select="name"/>
                    </xsl:element>
                  </td>
                  <td>
                    <!-- Details Links -->
                    <xsl:element name="a">
                      <xsl:attribute name="href">
                          <xsl:text disable-output-escaping="yes"><![CDATA[shop?action=detail_mb&id=]]></xsl:text><xsl:value-of select="id"/></xsl:attribute>
                      <xsl:text>Details</xsl:text>
                    </xsl:element>
                  </td>
                  <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">hidden</xsl:attribute>
                      <xsl:attribute name="name">motherboard_id</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>              
                    </xsl:element>
                </td>  
               </tr>
             </xsl:for-each>
             
        
        <tr bgcolor="silver"><td colspan = "2"><b>Processors:  </b></td></tr>
            <xsl:for-each select="processors/processor">
              <tr>
                 <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">radio</xsl:attribute>
                      <xsl:if test="position()=1">
                         <xsl:attribute name="checked">checked</xsl:attribute>
                      </xsl:if>
                      <xsl:attribute name="name">processor_radio</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="name"/></xsl:attribute>              
                    <xsl:value-of select="name"/>
                    </xsl:element>
                  </td>
                  <td>
                    <!-- Details Links -->
                    <xsl:element name="a">
                      <xsl:attribute name="href">
                          <xsl:text disable-output-escaping="yes"><![CDATA[shop?action=detail_proc&id=]]></xsl:text><xsl:value-of select="id"/></xsl:attribute>
                      <xsl:text>Details</xsl:text>
                    </xsl:element>
                  </td>
                  <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">hidden</xsl:attribute>
                      <xsl:attribute name="name">processor_id</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>              
                    </xsl:element>
                </td>  
                </tr>
             </xsl:for-each>
             
        
        <tr bgcolor="silver"><td colspan = "2"><b>RAM:  </b></td></tr>
            <xsl:for-each select="rams/ram">
              <tr>
                 <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">radio</xsl:attribute>
                      <xsl:if test="position()=1">
                         <xsl:attribute name="checked">checked</xsl:attribute>
                      </xsl:if>
                      <xsl:attribute name="name">ram_radio</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="name"/></xsl:attribute>              
                    <xsl:value-of select="name"/>
                    </xsl:element>
                 </td>
                 <td>
                    <!-- Details Links -->
                    <xsl:element name="a">
                      <xsl:attribute name="href">
                          <xsl:text disable-output-escaping="yes"><![CDATA[shop?action=detail_ram&id=]]></xsl:text><xsl:value-of select="id"/></xsl:attribute>
                      <xsl:text>Details</xsl:text>
                    </xsl:element>
                 </td>
                 <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">hidden</xsl:attribute>
                      <xsl:attribute name="name">ram_id</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>              
                    </xsl:element>
                </td>  
               </tr>
             </xsl:for-each>
             
        
        <tr bgcolor="silver"><td colspan = "2"><b>Videocards:  </b></td></tr>       
            <xsl:for-each select="videocards/videocard">
               <tr>
                  <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">radio</xsl:attribute>
                      <xsl:if test="position()=1">
                         <xsl:attribute name="checked">checked</xsl:attribute>
                      </xsl:if>
                      <xsl:attribute name="name">videocard_radio</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="name"/></xsl:attribute>              
                    <xsl:value-of select="name"/>
                    </xsl:element>
                  </td> 
                  <td>
                    <!-- Details Links -->
                    <xsl:element name="a">
                      <xsl:attribute name="href">
                          <xsl:text disable-output-escaping="yes"><![CDATA[shop?action=detail_vc&id=]]></xsl:text><xsl:value-of select="id"/></xsl:attribute>
                      <xsl:text>Details</xsl:text>
                    </xsl:element>
                 </td>
                 <td>
                    <xsl:element name="input">
                      <xsl:attribute name="type">hidden</xsl:attribute>
                      <xsl:attribute name="name">videocard_id</xsl:attribute>
                      <xsl:attribute name="value"><xsl:value-of select="id"/></xsl:attribute>              
                    </xsl:element>
                </td>  
               </tr>         
             </xsl:for-each> 
             <tr>
               <td>
                  <input type="button" value="Add to Shopping Cart" onClick="getRadioButtonsValues(componentlist_form)"/> 
               </td>
             </tr>
    </table>
    
    
     
    </form>
  </xsl:template>  
  
     
</xsl:stylesheet>
